package com.kugua.zfms.rank.impl;

import com.kugua.zfms.rank.Rank;
import com.kugua.zfms.rank.pojo.RankObject;
import com.kugua.zfms.rank.pojo.RankScore;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
 * <p>TODO</p>
 * <p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author cuiyh9
 * @version 1.0
 * @Date Created in 2019年01月07日 15:52
 * @since 1.0
 */
@Component
public class JvmRank implements Rank  {

    private TreeSet<Long> treeSet = new TreeSet<>();

    @Override
    public int size() {
        return treeSet.size();
    }

    @Override
    public Set<Long> page(int page, int size) {
        return null;
    }

    @Override
    public Set<Long> list() {
        return treeSet;
    }

    @Override
    public void add(RankObject rankObject) {
        treeSet.add(rankObject.getId());
    }

    @Override
    public int getRank(long id) {
        Iterator<Long> it = treeSet.iterator();
        int index = 0;
        while (it.hasNext()) {
            index ++;
            Long rs = it.next();
            if (rs.longValue() == id) {
                return index;
            }
        }
        return 0;

    }
}
